package com.sc.nft.entity.vo;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;
import com.sc.nft.entity.PledgeTaskReward;
import com.sc.nft.enums.PledgeStatusEnum;
import com.sc.nft.enums.PledgeTaskRewardTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
public class PledgeSecretAreaDetailsVO {

    @ApiModelProperty("id")
    private Long id;

    @ApiModelProperty("藏品名称")
    private String firstTitle;

    @ApiModelProperty("质押数量")
    private Integer pledgeCount;

    @ApiModelProperty("剩余时间")
    private Long completeTime;

    @ApiModelProperty("完成时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    protected Date endTime;

    @ApiModelProperty("质押状态  IN_PLEDGE:质押中 END_OF_PLEDGE:质押结束")
    private PledgeStatusEnum pledgeStatus;

    @ApiModelProperty("开始挖宝时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "藏品信息")
    private List<UserVigorousCollectionVO> userVigorousCollectionList;

    @ApiModelProperty(value = "挖宝奖励信息")
    private List<PledgeTaskRewardVO> pledgeTaskRewardVOList;


    public void setPledgeTaskRewardVOList(List<PledgeTaskReward>  list) {
        List<PledgeTaskRewardVO> pledgeTaskRewardList = Lists.newArrayList();
        if(list.size() == 0){
            this.pledgeTaskRewardVOList = pledgeTaskRewardList;
        }

        for (PledgeTaskReward pledgeTaskReward : list) {
            PledgeTaskRewardVO pledgeTaskRewardVO = BeanUtil.copyProperties(pledgeTaskReward, PledgeTaskRewardVO.class);
            if(pledgeTaskReward.getLinkType() == PledgeTaskRewardTypeEnum.POINTS){
                pledgeTaskRewardVO.setLinkCount(pledgeTaskReward.getLinkCount().setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
            }

            if(pledgeTaskReward.getLinkType() == PledgeTaskRewardTypeEnum.EQUITY_PROP || pledgeTaskReward.getLinkType() == PledgeTaskRewardTypeEnum.NFT){
                pledgeTaskRewardVO.setLinkCount(pledgeTaskReward.getLinkCount().stripTrailingZeros().toPlainString());
            }
            pledgeTaskRewardList.add(pledgeTaskRewardVO);
        }
        this.pledgeTaskRewardVOList = pledgeTaskRewardList;

    }
}
